package com.dingwei.superiordiary.ui.activity;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.allen.library.SuperButton;
import com.dingwei.superiordiary.R;
import com.dingwei.superiordiary.adapter.adapter.ServiceLogAdapter;
import com.dingwei.superiordiary.adapter.easyViewHolder.TuijianHolder;
import com.dingwei.superiordiary.adapter.easyViewHolder.WaitAuditHolder;
import com.dingwei.superiordiary.bean.ServiceLogBean;
import com.dingwei.superiordiary.mvp.presenter.WaitAuditPresenter;
import com.dingwei.superiordiary.mvp.view.Contract;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
import com.jude.easyrecyclerview.decoration.DividerDecoration;
import com.lihao.baselibrary.base.BaseActivity;
import com.lihao.baselibrary.utils.DisplayUtil;
import com.lihao.baselibrary.utils.IntentUtils;
import com.lihao.baselibrary.weight.TitleBar;
import com.umeng.socialize.media.Base;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created time 2018/1/17.
 * Creator 南柯一梦丶 on
 * Personal signature 余生还长 何必慌张
 * Page description :
 */

public class WaitAuditActivity extends BaseActivity implements Contract.WaitAuditView {

    WaitAuditPresenter waitAuditPresenter = new WaitAuditPresenter(this);
    @Bind(R.id.main_titleBar)
    TitleBar mainTitleBar;
    @Bind(R.id.m_recyclerView)
    RecyclerView mRecyclerView;
    @Bind(R.id.btn_submit)
    SuperButton btnSubmit;
    @Bind(R.id.data_layout)
    LinearLayout dataLayout;
    @Bind(R.id.no_net_btn)
    TextView noNetBtn;
    @Bind(R.id.no_net_layout)
    RelativeLayout noNetLayout;

    private String id;

    @Override
    protected int getContentViewId() {
        return R.layout.activity_wait_audit;
    }

    ServiceLogAdapter adapter;

    @Override
    protected void initData() {
        waitAuditPresenter.initData(id);
    }

    @Override
    protected void initView() {

        mainTitleBar.setTitleText("售后进度");
        id = getIntent().getStringExtra("id");
        LinearLayoutManager layoutManager = new LinearLayoutManager(context);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        mRecyclerView.setLayoutManager(layoutManager);
        mRecyclerView.setNestedScrollingEnabled(false);
        adapter = new ServiceLogAdapter(BaseActivity.context);
        mRecyclerView.setAdapter(adapter);
    }

    @Override
    protected void initListener() {
        mainTitleBar.setOnMenuListener(new TitleBar.OnMenuListener() {
            @Override
            public void onMenuClick() {
                intent = IntentUtils.getDialIntent("010-84909202");
                startActivity(intent);
            }
        });
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.btn_submit, R.id.no_net_btn})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_submit:
                if (btnSubmit.getText().toString().equals("提交单号")){
                    intent.setClass(context, FillInLogisticsNumberActivity.class);
                    startActivity(intent);
                }else {
                    finish();
                }
                break;
            case R.id.no_net_btn:
                waitAuditPresenter.initData(id);
                break;
        }
    }

    @Override
    public void onFail() {
        showData("fail");
    }

    @Override
    public void getData(ServiceLogBean bean) {
        adapter.addAll(bean.data.log);
        btnSubmit.setVisibility(View.GONE);
        showData("success");
    }

        public void showData(String state) {
                if (state.equals("success")) {
                   dataLayout.setVisibility(View.VISIBLE);
                   noNetLayout.setVisibility(View.GONE);
                } else {
                    dataLayout.setVisibility(View.GONE);
                    noNetLayout.setVisibility(View.VISIBLE);
                }
            }
}
